'use strict';
module.exports = {
	/**
	 * 查询用户记账类型
	 * @url client/typeData/kh/getTypeDataList 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _, $ } = util;
		let { uid } = data;
		let res = { code: 0, msg: "查询成功" };
		// 业务逻辑开始-----------------------------------------------------------
		let {pagination} = data
		// 查询所有初始数据
		let initDataList = await vk.daoCenter.typeDateDao.select({
			pageIndex: pagination.pageIndex, // 查询第几页
			pageSize: pagination.pageSize, // 每页多少条数据
			getCount: false,
			getMain: false,
			whereJson: {
				isCustomize:false,
				uid: "admin"
			},
			fieldJson: {
				_id:true,
				isCustomize:true,
				uid:true,
				icon:true,
				name:true,
				isExtend:true
			},
			sortArr: [{ "name":"_id", "type":"asc" }],
		});
		
		// 查询用户关联数据
		let customizeDataList = await vk.daoCenter.typeDateDao.select({
			pageIndex: pagination.pageIndex, // 查询第几页
			pageSize: pagination.pageSize, // 每页多少条数据
			getCount: false,
			getMain: false,
			whereJson: {
				isCustomize:true,
				uid: uid
			},
			fieldJson: {
				_id:true,
				isCustomize:true,
				uid:true,
				icon:true,
				name:true,
				isExtend:true
			},
			sortArr: [{ "name":"_id", "type":"asc" }],
		});

		let rtnData = []
		if (pubFun.isNotEmpty(initDataList) && initDataList.total > 0) {
			rtnData = initDataList.rows
		}
		if (pubFun.isNotEmpty(customizeDataList) && customizeDataList.total > 0) {
			rtnData = [...rtnData,...customizeDataList.rows]
		}
		
		let initPageParam = {
			data:rtnData,
			getCount: false,
			hasMore: false,
			pagination:{
				"pageIndex": 0,
				"pageSize": 1000
			},
			total: rtnData.length
		}
		res.data = initPageParam
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}